/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.pig.pigpen.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

import org.apache.hadoop.conf.Configuration;
import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
import org.apache.pig.backend.executionengine.ExecException;
import org.apache.pig.backend.hadoop.datastorage.ConfigurationUtil;

public class LaunchExampleGenerator {

    /**
     * @param args
     *            args[0] = PigScript args[1] = Output File args[2] = path to
     *            hadoop-site, pig.properties
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        File in = new File(args[0]);
        File out = new File(args[1]);
        StringBuffer script = new StringBuffer();
        PigServer pigServer;

        try {

            FileReader reader = new FileReader(in);
            BufferedReader buf = new BufferedReader(reader);
            for (String temp = buf.readLine(); temp != null; temp = buf
                    .readLine())
                script.append(temp);

            Configuration conf = new Configuration();
            conf.addResource((new File(args[2] + "hadoop-site.xml")).toURI()
                    .toURL());

            Properties properties = ConfigurationUtil.toProperties(conf);

            pigServer = new PigServer(ExecType.MAPREDUCE, properties);

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 

    }

}
